575H - Bots - CodeForces Solution


combinatorics dp math number theory *1800

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
const int N=2e6+2;
const int M=1e6;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
int n;
int fac[N+5],inv[N+5];
int qpow(int a,int b){
	int c=1;
	while(b){
		if(b&1)c=1LL*c*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return c;
}
int C(int n,int m){
	return 1LL*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	fac[0]=1;
	for(int i=1;i<=N;i++)fac[i]=1LL*i*fac[i-1]%mod;
	inv[N]=qpow(fac[N],mod-2);
	for(int i=N-1;i>=0;i--)inv[i]=1LL*(i+1)*inv[i+1]%mod;
	int ans=1;
	for(int i=2;i<=n+1;i++){
		int tmp=(mod+C(i*2,i)-C(2*i-2,i-1))%mod;
		ans=(ans+tmp)%mod;
	}
	cout<<ans;
	return 0;
}


Comments

Submit
0 Comments
More Questions

1455B - Jumps
1225C - p-binary
1525D - Armchairs
1257A - Two Rival Students
1415A - Prison Break
1271A - Suits
259B - Little Elephant and Magic Square
1389A - LCM Problem
778A - String Game
1382A - Common Subsequence
1512D - Corrupted Array
667B - Coat of Anticubism
284B - Cows and Poker Game
1666D - Deletive Editing
1433D - Districts Connection
2B - The least round way
1324A - Yet Another Tetris Problem
246B - Increase and Decrease
22E - Scheme
1566A - Median Maximization
1278A - Shuffle Hashing
1666F - Fancy Stack
1354A - Alarm Clock
1543B - Customising the Track
1337A - Ichihime and Triangle
1366A - Shovels and Swords
919A - Supermarket
630C - Lucky Numbers
1208B - Uniqueness
1384A - Common Prefixes